/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.rakev.producer;

/**
 *
 * @author Rakev
 */
public class CompositeProducer<F, T, M> implements Producer<F, T> {

    private Producer<F, M> firstProducer;
    private Producer<M, T> secondProducer;

    public CompositeProducer(Producer<F, M> firstProducer, Producer<M, T> secondProducer) {
        this.firstProducer = firstProducer;
        this.secondProducer = secondProducer;
    }

    @Override
    public T produce(F fromObject) {
        M firstValue = firstProducer.produce(fromObject);
        if (firstValue != null) {
            return secondProducer.produce(firstValue);
        } else {
            return null;
        }
    }
}
